package com.masterclient.app.modules.main.manager;

import android.content.Context;

import com.masterclient.app.modules.main.beans.ScanWelfareBean;
import com.masterclient.app.modules.main.widget.ScanWelfareDialog;
import com.masterclient.app.modules.main.widget.ScanWelfareFailureDialog;

/**
 * @auther hjian
 * @date 2020/7/29.
 */
public class ScanManager {

    private static ScanManager scanManager;

    public static ScanManager getScanManager() {
        if (scanManager == null) {
            scanManager = new ScanManager();
        }
        return scanManager;
    }

    public ScanWelfareBean welfareBean;
    public String code;
    /**
     * 关闭dialog 为 null
     */
    public ScanWelfareDialog welfareSuccessDialog;
    public ScanWelfareFailureDialog welfareFailuredialog;

    public boolean isShowDialog(){
        return welfareSuccessDialog != null || welfareFailuredialog != null;
    }
    /**
     * 福利获取弹窗
     * @param context
     */
    public void showWelfareDialog(Context context){
        if (welfareBean != null) {
            if ("0".equals(welfareBean.getPop_code())) {
                showWelfareSuccessDialog(context);
            } else {
                showWelfareFailureDialog(context);
            }
        }
    }

    /**
     * 福利获取成功弹窗
     * @param context
     */
    private void showWelfareSuccessDialog(Context context) {
        welfareSuccessDialog = new ScanWelfareDialog(context,code,welfareBean.getData());
        welfareSuccessDialog.show();
    }

    /**
     * 福利获取失败弹窗
     * @param context
     */
    private void showWelfareFailureDialog(Context context) {
        welfareFailuredialog = new ScanWelfareFailureDialog(context,welfareBean.getErr_msg(),
                "2".equals(welfareBean.getPop_code())?welfareBean.getErr_data():null,null);
        welfareFailuredialog.show();
    }


}
